package com.ai.controller.made.ai_api;


import com.ai.annotation.EnterPathParamLog;
import com.ai.common.CommonResponse;
import com.ai.entity.made.CoalMaintenanceAlarmRecordInfo;
import com.ai.entity.made.camera.CameraIdBO;
import com.ai.entity.network.L1ToIdentifySysMessage;
import com.ai.modbus.ModbusProvide;
import com.ai.model.dto.PlatCameraDto;
import com.ai.model.param.AlgorithmBindServerParam;
import com.ai.model.vo.BatchOperateCameraParam;
import com.ai.opc.KEPOpcDemo5;
import com.ai.opc.OpcClient4;
import com.ai.service.made.AlgorithmCameraService;
import com.ai.service.made.ICoalMaintenanceAlarmRecordService;
import com.ai.service.made.impl.CoalMaintenanceAlarmRecordInfoServiceImpl;
import com.ai.util.GetCameraInfoHk;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.math.raw.Mod;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 算法接口----摄像头开关算法
 * @author jiaok
 * @since 2023-04-03 21:17:12
 */
@RestController
@RequestMapping("/algorithmAPI/camera")
@Slf4j
public class CameraAPI {

    @Resource
    AlgorithmCameraService algorithmCameraService;


    @Resource
    ICoalMaintenanceAlarmRecordService maintenanceAlarmRecordService;


    @Resource
    private GetCameraInfoHk getCameraInfoHk;

    @Resource
    ModbusProvide modbusProvide;


    @Resource
    OpcClient4 opcClient4;

    @Resource
    KEPOpcDemo5 kepOpcDemo5;

    @PostMapping("getCameraIdsByType")
    @ApiOperation("获取对应功能摄像头")
    @EnterPathParamLog
    public CommonResponse getCameraIdsByType(@RequestBody AlgorithmBindServerParam param) {
       return  algorithmCameraService.getCameraIdsByType(param);
    }


    /**
     * 打开摄像头
     */
    @PostMapping("onOpen")
    @ApiOperation("打开摄像头")
    @EnterPathParamLog
    public CommonResponse onOpen(@RequestBody CameraIdBO cameraIdBO) {
        CommonResponse resultData = algorithmCameraService.onOpen(cameraIdBO);
        log.info(resultData.toString());
        return resultData;
    }

    @PostMapping("batchOpening")
    @ApiOperation("批量开启摄像头")
    @EnterPathParamLog
    public CommonResponse batchOpening(@RequestBody BatchOperateCameraParam batchOperateCameraParam) {
        CommonResponse resultData = algorithmCameraService.batchOpening(batchOperateCameraParam);
        return resultData;
    }



    /**
     * 关闭摄像头
     */
    @PostMapping("onClose")
    @ApiOperation("关闭摄像头")
    @EnterPathParamLog
    public CommonResponse onClose(@RequestBody CameraIdBO cameraIdBO) {
        CommonResponse resultData = algorithmCameraService.onClose(cameraIdBO);
        log.info(resultData.toString());
        return resultData;
    }

    /**
     * 检测启动
     */
    @PostMapping("detectionStart")
    @ApiOperation("检测启动")
    public CommonResponse detectionStart() {
        CommonResponse resultData = algorithmCameraService.detectionStart();
        log.info(resultData.toString());
        return resultData;
    }


    @PostMapping("test")
    @ApiOperation("检测启动")
    public CommonResponse test() {
      return maintenanceAlarmRecordService.test();
    }


    @GetMapping("getNodeValue/{offset}/{slave}")
    @ApiOperation("modbus读取值测试")
    public CommonResponse getNodeValue(@PathVariable(value = "offset") Integer offset, @PathVariable(value = "slave")Integer slave) {
        return modbusProvide.getNodeValue(offset,slave);
    }


    @GetMapping("/connectOpc/{nameSpaceIndex}/{identifier}")
    @ApiOperation("检测启动")
    public CommonResponse getOpcConnect(@PathVariable(value = "nameSpaceIndex") Integer nameSpaceIndex
            ,@PathVariable(value = "identifier") String identifier) {

        return kepOpcDemo5.getOpcConnect(nameSpaceIndex,identifier);

    }


    @GetMapping("/getCameraInfo/{name}/{platId}")
    @ApiOperation("平台获取摄像头信息接口测试1")
    public CommonResponse getCameraInfo(@PathVariable(value = "name") String name
            ,@PathVariable(value = "platId") String platId) {
        List<HashMap<String, String>> cameraInfo = getCameraInfoHk.getCameraInfo(Integer.valueOf(platId), name);
        return CommonResponse.ok(cameraInfo);
    }

    @GetMapping("/getCameraInfo1/{name}/{platId}")
    @ApiOperation("平台获取摄像头信息接口测试2")
    public CommonResponse getCameraInfo1(@PathVariable(value = "name") String name
            ,@PathVariable(value = "platId") String platId) {
        String cameraInfo = getCameraInfoHk.getCameraInfoStr1(Integer.valueOf(platId), name);
        return CommonResponse.ok(cameraInfo);
    }




    @GetMapping("/getCameraInfo2/{name}/{platId}")
    @ApiOperation("平台获取摄像头信息接口测试3")
    public CommonResponse getCameraInfo2(@PathVariable(value = "name") String name
            ,@PathVariable(value = "platId") String platId) {
        String cameraInfo = getCameraInfoHk.getCameraInfoStr2(Integer.valueOf(platId), name);
        return CommonResponse.ok(cameraInfo);
    }



}
